package org.gwu.seuss.communication.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Password Policy
 * Must contains one digit from 0-9
 * Must contains one lowercase characters
 * Must contains one uppercase characters
 * Must contains one special symbols in the list "@#$%"
 * Must have a length at least 8 characters and maximum of 20	
 *
 */
public class PasswordValidator {
	private Pattern pattern;
	private Matcher matcher;

	private static final String PASSWORD_PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{8,20})";

	public PasswordValidator() {
		pattern = Pattern.compile(PASSWORD_PATTERN);
	}

	/**
	 * Validate password with regular expression
	 * 
	 * @param password
	 *            password for validation
	 * @return true valid password, false invalid password
	 */
	public boolean validate(final String password) {

		matcher = pattern.matcher(password);
		return matcher.matches();

	}
}